<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"
    import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>修改設備資料</title>
<script language="JavaScript">
  function formCheck()
  {
     if(document.form1.fid.value == ""){
	      alert("請填寫設備編號");
		  document.form1.fid.focus()
		  return false;
	 }
	 if(document.form1.fname.value == ""){
	      alert("請填寫設備名稱");
		  document.form1.fname.focus()
		  return false;
	 }	 
	 if(document.form1.fdetail.value == ""){
	      alert("請填寫設備描述");
		  document.form1.fdetail.focus()
		  return false;
	 }
  }
</script>
</head>
<body>
<% if(session.getAttribute("access") == "y" ){%>
<jsp:useBean id="mydb" scope="page" class="bean.ConDbBean"/> <%//連結資料庫的bean %>
<% 
	  String sql="select * from FACILITY WHERE F_ID='"+request.getParameter("fid")+"'";
	  ResultSet rs=mydb.executeQuery(sql); 
	  rs.next();
	  String fstate=rs.getString("F_STATE");
	  sql="select * from FACILITY_CLASS ";
	  ResultSet rs2=mydb.executeQuery(sql);
	  %>
	  
<table width="750" border="0" align="center">
  <tr>
    <td width="30" rowspan="4"><jsp:include page="../frameset/left.jsp" flush="true" ></jsp:include></td>
    <td colspan="2"><jsp:include page="../frameset/top.jsp" flush="true" ></jsp:include></td>
    <td width="40" rowspan="4"><jsp:include page="../frameset/right.jsp" flush="true" ></jsp:include></td>
  </tr>
  <tr>
    <td rowspan="2"><jsp:include page="../frameset/mean.jsp" flush="true" ></jsp:include>

    </td>
    <td height="32"><jsp:include page="../frameset/pfm_mean.jsp" flush="true" ></jsp:include></td>
  </tr>
  <tr>
    <td>
    <table width="500" border="0" align="center">
  <tr>
    <td><form id="form1" name="form1" method="post" action="do_alterFacility.jsp">
	<table width="400" border="1" align="center">
  <tr>
    <td>設備編號</td>
    <td><input type="hidden" name="oldid" value="<%=rs.getString("F_ID")%>"><input type="text" name="fid" value="<%=rs.getString("F_ID")%>"/></td>
  </tr>
  <tr>
    <td>設備類別</td>
    <td>
        <select name="class">
    <% while(rs2.next()){
    
    	if(rs.getString("F_CLASS").equalsIgnoreCase(rs2.getString("FC_ID"))){%>
    		<option value="<%=rs2.getString("FC_ID")%>" selected="selected"><%=rs2.getString("FC_NAME")%></option>
    	<%
    	
    	}
    	else{
    	%>
    	<option value="<%=rs2.getString("FC_ID")%>"><%=rs2.getString("FC_NAME")%></option>
    	<%
    		}
    }
    %>
  		</select>
    </td>
  </tr>
  <tr>
    <td>設備名稱</td>
    <td><input type="text" name="fname" value="<%=rs.getString("F_NAME")%>"/></td>
  </tr>
  <tr>
    <td>設備描述</td>
    <td><textarea name="fdetail" rows="5" cols="30"><%=rs.getString("F_DETAIL")%></textarea></td>
  </tr>
  <tr>
    <td>狀態</td>
    <td>
    
    <select name="fstate">
    <option value="00" <% if(fstate.equalsIgnoreCase("00")) out.print("selected");%>>可使用</option>
    <option value="01" <% if(fstate.equalsIgnoreCase("01")) out.print("selected");%>>預借中</option>
    <option value="10" <% if(fstate.equalsIgnoreCase("10")) out.print("selected");%>>借用中</option>
    <option value="11" <% if(fstate.equalsIgnoreCase("11")) out.print("selected");%>>逾期 </option>
    </select>
    </td>
  </tr>
  <tr>
    <td>備註</td>
    <td><textarea name="fps" rows="5" cols="30"><%=rs.getString("PS")%></textarea></td>
  </tr>
   <tr>
    <td colspan="2"><div align="center">
      <input name="重新填寫" type="reset" value="重新填寫" />      
      <input name="" type="submit" value="確定" onClick="return formCheck()"/>
    </div></td>
  </tr>
</table>
    </form>
    </td>
  </tr>
</table>
    </td>
  </tr>
  <tr>
    <td colspan="2"></td>
  </tr>
</table>
<%
  }
  else{
  	response.sendRedirect("../index.jsp"); //若沒有登入則回到index.jsp
  } 
  %>
</body>
</html>